package cm.com.carlamanda.service.impl;

import java.util.List;
import java.util.UUID;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.bosch.util.Md5Util;

import cm.com.carlamanda.dao.UserDAO;
import cm.com.carlamanda.domain.UserInfo;
import cm.com.carlamanda.service.UserService;
@Service
public class UserServiceImpl implements UserService{
    @Autowired
    private UserDAO userDao;
    

    @Override
    public UserInfo getUser(UserInfo userInfo) {
        return userDao.findUserByNamePassword(userInfo);
    }

    @Override
    public List<UserInfo> searchUser(UserInfo userSearchInfo) {
        return userDao.searchUsers(userSearchInfo);
    }

    @Override
    public void editUser(UserInfo userInfo) {
         userDao.editUser(userInfo);
    }

    @Override
    public void delUser(String userNo) {
         userDao.delUser(userNo);
    }

    @Override
    public void addUser(UserInfo userInfo) {
        if(StringUtils.isEmpty(userInfo.getUuId())){
            userInfo.setUuId(UUID.randomUUID().toString());
        }
        String password = userInfo.getPassword();
        userInfo.setPassword(Md5Util.getMD5(password));
        userDao.insertUser(userInfo);
    }


    public void setUserDao(UserDAO userDao) {
        this.userDao = userDao;
    }
    
}
